/* A module for all user interface events */
$(document).on('mousedown', '#splash', function() {
    game.ui.hideSplash(function() {
    });
});

function UI() {
    this.init = function() {
        game.pause();
        this.splash();
    }
    
    this.splash = function(callback) {
    
    }
    
    
    this.hideSplash = function(callback) {
        $('#splash').fadeOut(400, callback);
        var text = '<p><b>' + game.logic.person.name + ': </b></p><ul>';
        var flag = true;
        for (var trait in game.logic.person.traits) {
            text += '<li><b>' + game.logic.person.traits[trait].name + '</b>: ' + game.logic.person.traits[trait].description + '</li>'; 
        }
        text += '</ul>';
        
        var traits = {
            name: "Your character traits",
            description: text
        };
        game.ui.inventory(traits, function() { 
        });
    }
    
    this.characters = function(chars, callback) {
        game.pause();
        
        game.unpause();
        callback();
    }
    
    this.opportunity = function(type, opps, callback) {
        game.pause();
        $('#opportunity-choices').html('');
        $('#opportunity-building').html(type);
        for (var opp in opps) {
            var op = opps[opp];
            var stuff = $('<button id="' + type + '-opp-' + opp + '">' + op.name + ': <br>' + op.description + '</button>');
            stuff.data('cb', callback);
            stuff.data('op', op);
            stuff.bind('click', function() {
                $('#opportunities').fadeOut(200);
                $(this).data('cb')($(this).data('op'));
                game.unpause();
            });
            $('#opportunity-choices').append(stuff);
        }
        $('#opportunities').fadeIn(200);
    }
    
    this.inventory = function(inv, callback) {
        game.pause();
        $('#inventory-words').html(inv.description);
        $('#inventory').fadeIn(200);
        $(document).on('click', '#inventory-ok', function() {
            $('#inventory').fadeOut(200);
            game.unpause();
            callback();
        });
    }

    this.win = function(won, reason, callback) {
        game.pause();
        if (won) {
            game.updateDashboard();
            alert('you won because ' + reason);
        } else {
            game.updateDashboard();
            alert('you lost because ' + reason);
        }
        callback();
    }
    
    this.writeConsole = function(words) {
        var para = $('<p>' + words + '</p>');
        para.css('display', 'none');
        $('#game-console').prepend(para);
        para.slideDown(1000);
    }
}